/*
 * Address.cpp
 *
 *  Created on: 31 Μαϊ 2010
 *      Author: Sartios
 */

#include "Address.h"

#include "../../../Validators/AddressValidators/TownValidators/TownValidator.h"
#include "../../../Validators/AddressValidators/StreetValidators/StreetValidator.h"
#include "../../../Validators/AddressValidators/NumberValidators/StreetNumberValidator.h"

Address::Address() {
	town_=NULL;
	street_=NULL;
	number_=NULL;
}

Address::~Address() {
	delete town_;
	delete street_;
	delete number_;
}
Address::Address(const string *town,const string *street,const string *number){
	if((NULL!=town)&&(NULL!=street)&&(NULL!=number)){
		setTown(town);
		setStreet(street);
		setNumber(number);
	}
}

void		Address::setTown(const string *town){
	if(NULL!=town){
		TownValidator townValidator;
		if(townValidator.townNameHasAppropriateLength(town)&&(townValidator.townNameContainsValidContent(town))){
			town_=new string(*town);
		}
		else{
			town_=NULL;
		}
	}
	else{
		town_=NULL;
	}
}

string	*	Address::getTown()const{
	return town_;
}

void		Address::setStreet(const string *street){
	if(NULL!=street){
		StreetValidator streetValidator;
		if(streetValidator.streetNameHasAppropriateContent(street)){
			street_=new string(*street);
		}
		else{
			street_ = NULL;
		}
	}
	else{
		street_= NULL;
	}
}

string	*	Address::getStreet()const{
	return street_;
}

void		Address::setNumber(const string *number){
	if(NULL!=number){
		StreetNumberValidator numValidator;
		if(numValidator.streetNumberHasAppropriateContent(number)){
			number_=new string(*number);
		}
		else{
			number_ = NULL;
		}
	}
	else{
		number_ = NULL;
	}

}

string	*	Address::getNumber()const{
	return number_;
}

